package com.tistory.wonsama.util;

import java.util.ArrayList;
import java.util.Collections;

public class WMath {
	
	/**
	 * 로또 넘버를 생성한다 6/45
	 * @return 로또
	 */
	public static Integer[] getLotto()
	{
		final int NUM_START = 1;
		final int NUM_END = 45;
		final int NUM_COUNT = 6;
		
		ArrayList<Integer> lotto = new ArrayList<Integer>();
		
		for( int i=0 ; i<NUM_COUNT ; i++ ){
			int rnd = getRandInt( NUM_START , NUM_END );
			int frequency = Collections.frequency( lotto , rnd);
			if( frequency == 0 ){
				lotto.add( rnd );
			}else{
				i--;
			}
		}
		
		//SORT
		WSort.sortInteger( lotto );
		
		Integer[] rtnValue = new Integer[ lotto.size() ]; 
		return lotto.toArray( rtnValue );
	}
	
	public static int getRandInt( int start, int end )
	{
		return (int) ( Math.random() * (end - start + 1) ) + start  ;
	}
}
